package com.couldtest.consumerRibbonHystrix;

import com.netflix.hystrix.HystrixCommand;
import org.springframework.web.client.RestTemplate;

public class MyCommand  extends HystrixCommand<String> {

    private RestTemplate restTemplate;

    @Override
    protected String getFallback() {
        //捕获调用过程中的异常
        Throwable executionException = getExecutionException();

        return "请求处理失败 fallBack";
    }

    @Override
    protected String run() throws Exception {
        return   restTemplate.getForObject("http://provider/dcx", String.class);
    }



    public MyCommand(Setter setter, RestTemplate restTemplate) {
        super(setter);
        this.restTemplate = restTemplate;
    }
}
